package com.yzt.zhuju.mvp;


import com.yzt.zhuju.rx.LifecycleTransformer;

import io.reactivex.Observable;

/**
 * <pre>
 *     author : TK
 *     desc   : 封装Presenter层
 * </pre>
 */
public abstract class BasePresenter<V extends Contract.IView> implements Contract.IPresenter<V> {

    protected V mView;

    @Override
    public void attach(V view) {
        mView = view;
    }

    @Override
    public void detach() {
        mView = null;
    }

    public <T> LifecycleTransformer<T> bindOnDestroy() {
        if (mView == null) {
            return new LifecycleTransformer<>(Observable.just(new Object()));
        }
        return mView.bindOnDestroy();
    }
}
